package edu.sandau.basic.service.impl;

import edu.sandau.basic.domain.Menu;
import edu.sandau.basic.mapper.MenuMapper;
import edu.sandau.basic.service.MenuService;
import edu.sandau.basic.vo.BasicMsg;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {

    @Resource
    private MenuMapper menuMapper;

    @Override
    public List<Menu> listAll() {
        return menuMapper.selectAll();
    }

    @Override
    public Menu getById(Integer id) {
        return menuMapper.selectById(id);
    }

    @Override
    public BasicMsg add(Menu menu) {
        menu.setMenu_id(null);
        int res = menuMapper.insert(menu);
        return res == 1 ? BasicMsg.ok("新增菜单成功") : BasicMsg.error("新增失败");
    }

    @Override
    public BasicMsg update(Menu menu) {
        int res = menuMapper.update(menu);
        return res == 1 ? BasicMsg.ok("更新菜单成功") : BasicMsg.error("更新失败");
    }

    @Override
    public BasicMsg delete(Integer id) {
        int res = menuMapper.delete(id);
        return res == 1 ? BasicMsg.ok("删除成功") : BasicMsg.error("删除失败");
    }
}
